package com.jiyici.model;

import org.json.JSONException;
import org.json.JSONObject;

import jiyici.Constant.ModelColumn;
import android.content.ContentValues;
import android.database.Cursor;

public class ItemParam extends ClientBaseModel {

    private static final long serialVersionUID = 4821466124352542481L;

    public long itemId;

    public String itemParamName;

    public int paramType;

    public boolean isMust;
    
    public String displayOrder;
    
    @Override
    public ContentValues toContentValues() {
        ContentValues values = super.toContentValues();
        values.put(ModelColumn.ITEM_PARAM_COLUMN_ITEMID, itemId);
        values.put(ModelColumn.ITEM_PARAM_COLUMN_NAME, itemParamName);
        values.put(ModelColumn.ITEM_PARAM_COLUMN_TYPE, paramType);
        values.put(ModelColumn.ITEM_PARAM_COLUMN_IS_MUST, isMust);
        values.put(ModelColumn.ITEM_PARAM_COLUMN_DISPLAY_ORDER, displayOrder);
        return values;
    }
    
    @Override
    public void fromCursor(Cursor c) {
        super.fromCursor(c);
        itemId = c.getLong(c.getColumnIndex(ModelColumn.ITEM_PARAM_COLUMN_ITEMID));
        itemParamName = c.getString(c.getColumnIndex(ModelColumn.ITEM_PARAM_COLUMN_NAME));
        paramType = c.getInt(c.getColumnIndex(ModelColumn.ITEM_PARAM_COLUMN_TYPE));
        isMust = c.getInt(c.getColumnIndex(ModelColumn.ITEM_PARAM_COLUMN_IS_MUST)) > 0;
        displayOrder = c.getString(c.getColumnIndex(ModelColumn.ITEM_PARAM_COLUMN_DISPLAY_ORDER));
    }
    
    @Override
    public void fromJson(JSONObject json) throws JSONException {
        super.fromJson(json);
        itemId = json.getLong(ModelColumn.ITEM_PARAM_COLUMN_ITEMID);
        itemParamName = json.getString(ModelColumn.ITEM_PARAM_COLUMN_NAME);
        paramType = json.getInt(ModelColumn.ITEM_PARAM_COLUMN_TYPE);
        isMust = json.getBoolean(ModelColumn.ITEM_PARAM_COLUMN_IS_MUST);
        displayOrder = json.getString(ModelColumn.ITEM_PARAM_COLUMN_DISPLAY_ORDER);
    }
    
    @Override
    public JSONObject toJson() throws JSONException {
        JSONObject json = super.toJson();
        json.put(ModelColumn.ITEM_PARAM_COLUMN_ITEMID, itemId);
        json.put(ModelColumn.ITEM_PARAM_COLUMN_NAME, itemParamName);
        json.put(ModelColumn.ITEM_PARAM_COLUMN_TYPE, paramType);
        json.put(ModelColumn.ITEM_PARAM_COLUMN_IS_MUST, isMust);
        json.put(ModelColumn.ITEM_PARAM_COLUMN_DISPLAY_ORDER, displayOrder);
        return json;
    }

    @Override
    public String toString() {
        return "ItemParam [id=" + id + ", userId=" + userId + ", lastmodified=" + lastmodified + ", deleted=" + deleted
                + ", dirty=" + dirty + ", itemId=" + itemId + ", itemParamName=" + itemParamName + ", paramType="
                + paramType + ", isMust=" + isMust + "]";
    }
}
